package com.heima.article.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.injector.methods.SelectByMap;
import com.baomidou.mybatisplus.core.injector.methods.SelectOne;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.ApArticleConfigMapper;
import com.heima.article.mapper.ApArticleContentMapper;
import com.heima.article.service.ApArticleConfigService;
import com.heima.model.article.pojos.ApArticleConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;
import java.util.Map;
@Service
public class ApArticleConfigServiceImpl extends ServiceImpl<ApArticleConfigMapper, ApArticleConfig> implements ApArticleConfigService {

    @Autowired
    private ApArticleConfigMapper apArticleConfigMapper;
    /**
     * 修改文章配置
     * isDown
     *     true: 下架   1
     *     false: 没有下架  0
     * @param map
     */
    @Override
    public void updateByMap(Map map) {
        //enable 0 下架 1 上架
        Object enable = map.get("enable");
        boolean isDown = true;//1
        if(enable.equals(1)){
            isDown = false;//0
        }
        //根据articleid查出文章配置信息
        LambdaQueryWrapper<ApArticleConfig> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ApArticleConfig::getArticleId,map.get("articleId"));

        ApArticleConfig apArticleConfig = apArticleConfigMapper.selectOne(lambdaQueryWrapper);
        apArticleConfig.setIsDown(isDown);
        updateById(apArticleConfig);

    }
}
